package cn.gov.cus.rmftquartz.common.utils;

import cn.gov.cus.rmftquartz.common.Result;
import com.google.gson.Gson;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;

import javax.validation.constraints.NotNull;

/**
 * @author wxming.
 * @date 2018/2/9.
 */
@Component
public class HGLogHelper {
    private static final Logger log = LoggerFactory.getLogger(HGLogHelper.class);

    @Value("${logUrl")
    private String logUrl;

    public void byIOSystemLog(@NotNull String myModel,@NotNull Exception myeo){
        try {
            log.error(ExceptionHelper.getExMsg(myeo));
            RestTemplate restTemplate = new RestTemplate();
            String mye = ExceptionHelper.getExMsg(myeo);//实际使用中发现直接将异常类当参数传递时，对于500错误的异常，无法传递，猜测500异常是对于http有特殊意义的内容，不能当参数传递，所以直接提取字符串传递。
            MultiValueMap<String,Object> dataMap=new LinkedMultiValueMap<>();
            dataMap.add("myModel",myModel);
            dataMap.add("mye",mye);

            String url = logUrl+"/logController/writeSystemLogByString";
            //调用复合参数接口
            String rtn=restTemplate.postForObject(url,dataMap,String.class);

            Result<String> lst = new Gson().fromJson(rtn,Result.class);
            log.info("返回值：{}",lst);
        }catch(Exception e){

        }
    }

    public void byIOBusinessLog(@NotNull String myModel,@NotNull String myNote){

    }
}
